const INFO_KEY = 'vue2-learning-pro-7'
const DEFAULT_INFO = { token: '', userId: '' }

const HISTORY_KEY = 'vue2-learning-pro-7-history'
export const getInfo = () => {
  const info = localStorage.getItem(INFO_KEY)
  return info ? JSON.parse(info) : DEFAULT_INFO
}

export const setInfo = (info) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(info))
}

export const removeInfo = () => {
  localStorage.removeItem(INFO_KEY)
}

export const getHistory = () => {
  const result = localStorage.getItem(HISTORY_KEY)
  return result ? JSON.parse(result) : []
}

export const setHistory = (items) => {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(items))
}
